Unit BControllerCodePartsUnit;

{$mode objfpc}{$H+}

Interface

ResourceString
  CODE_PLAIN_GET_INFO =
    'Procedure B%1:sControllerClass.Get%0:sInfo(%2:s);\' +
    'Var\' +
    '  a%0:s: B%0:sClass;\' +
    'Begin\' +
    '  a%0:s := bManager.GetObject(a%0:sID);\' +
    '  MIf(a%0:s = nil)MThen(1, ''Unable find %0:s'')MExit;\' +
    '  //@PlainGetInfoStart\' +
    '  //@PlainGetInfoStop\' +
    'End;\' +
    ' \';

  CODE_PLAIN_UPDATE =
    'Procedure B%1:sControllerClass.Update%0:s(%2:s);\' +
    'Var\' +
    '  a%0:s: B%0:sClass;\' +
    '  //@PlainUpdateVarsStart\' +
    '  //@PlainUpdateVarsStop\' +
    'Begin\' +
    '  a%0:s := bManager.GetObject(a%0:sID);\' +
    '  MIf(a%0:s = nil)MThen(1, ''Unable find %0:s'')MExit;\' +
    '  a%0:s := bManager.ChangeObject(a%0:s);\' +
    '  //@PlainUpdateStart\' +
    '  //@PlainUpdateStop\' +
    '  a%0:s.Validate;\' +
    'End;\' +
    ' \';

  CODE_PEA_PLURAL_PLAIN_GET =
    'Function B%1:sControllerClass.Get%0:s%2:s(Const a%0:sID: Integer; ' +
      'Const aCallback: String; Var aErrorInfo: BErrorInfoRec): String;\' +
    'Var\' +
    '  i: Integer;\' +
    '  a%0:s: B%0:sClass;\' +
    'Begin\' +
    '  Result := '''';\' +
    '  a%0:s := bManager.GetObject(a%0:sID);\' +
    '  MIf(a%0:s = nil)MThen(1, ''Unable find %0:s'')MExit;\' +
    '  With a%0:s.%2:s.LockList Do\' +
    '    Try\' +
    '      For i := 0 To Count - 1 Do\' +
    '        AppendCommaString(Result, ''%3:s'', [%4:s])\' +
    '    Finally\' +
    '      a%0:s.%2:s.UnlockList;\' +
    '    End;\' +
    '  Result := ''['' + Result + '']'';\' +
    '  If Not(aCallback = '''') Then\' +
    '    Result := PrepareJSONP(aCallback, Result);\' +
    'End;\' +
    ' \' +
    'Procedure B%1:sControllerClass.Get%0:s%2:s(Const a%0:sID: Integer; ' +
      'Const aCallback: String; Var a%2:sString: String; ' +
      'Var aErrorInfo: BErrorInfoRec);\' +
    'Begin\' +
    '  a%2:sString := Get%0:s%2:s(a%0:sID, aCallback, aErrorInfo);\' +
    'End;\' +
    ' \';

  CODE_PEA_PLURAL_PEAS_GET =
    'Function B%1:sControllerClass.Get%0:s%2:s(Const a%0:sID: Integer; ' +
      'Const aCallback: String; Var aErrorInfo: BErrorInfoRec): String;\' +
    'Var\' +
    '  i: Integer;\' +
    '  a%0:s: B%0:sClass;\' +
    '  a%3:s: B%3:sClass;\' +
    '  a%4:sCtrl: B%4:sControllerClass;\' +
    'Begin\' +
    '  Result := '''';\' +
    '  a%0:s := bManager.GetObject(a%0:sID);\' +
    '  MIf(a%0:s = nil)MThen(1, ''Unable find %0:s'')MExit;\' +
    '  a%4:sCtrl := B%4:sControllerClass.Build;\' +
    '  With a%0:s.%2:s.LockList Do\' +
    '    Try\' +
    '      For i := 0 To Count - 1 Do\' +
    '        If Not(Items[i].Deleted) Then\' +
    '          AppendCommaString(Result, ''{%%s}'', ' +
                 '[a%4:sCtrl.GetJSON(Items[i])]);\' +
    '    Finally\' +
    '      a%4:sCtrl.Burn;\' +
    '      a%0:s.%2:s.UnlockList;\' +
    '    End;\' +
    '  Result := ''['' + Result + '']'';\' +
    '  If Not(aCallback = '''') Then\' +
    '    Result := PrepareJSONP(aCallback, Result);\' +
    'End;\' +
    ' \' +
    'Procedure B%1:sControllerClass.Get%0:s%2:s(Const a%0:sID: Integer; ' +
      'Const aCallback: String; Var a%2:sString: String; ' +
      'Var aErrorInfo: BErrorInfoRec);\' +
    'Begin\' +
    '  a%2:sString := Get%0:s%2:s(a%0:sID, aCallback, aErrorInfo);\' +
    'End;\' +
    ' \';

  CODE_PEA_PLURAL_HOLDERS_GET =
    'Function B%1:sControllerClass.Get%0:s%2:s(Const a%0:sID: Integer; ' +
      'Const aCallback: String; Var aErrorInfo: BErrorInfoRec): String;\' +
    'Var\' +
    '  i: Integer;\' +
    '  a%0:s: B%0:sClass;\' +
    '  a%3:s: B%3:sClass;\' +
    '  a%4:sCtrl: B%4:sControllerClass;\' +
    'Begin\' +
    '  Result := '''';\' +
    '  a%0:s := bManager.GetObject(a%0:sID);\' +
    '  MIf(a%0:s = nil)MThen(1, ''Unable find %0:s'')MExit;\' +
    '  a%4:sCtrl := B%4:sControllerClass.Build;\' +
    '  With a%0:s.%2:s.LockList Do\' +
    '    Try\' +
    '      For i := 0 To Count - 1 Do\' +
    '        AppendCommaString(Result, ''{%%s}'', ' +
               '[a%4:sCtrl.GetJSON(Items[i])]);\' +
    '    Finally\' +
    '      a%4:sCtrl.Burn;\' +
    '      a%0:s.%2:s.UnlockList;\' +
    '    End;\' +
    '  Result := ''['' + Result + '']'';\' +
    '  If Not(aCallback = '''') Then\' +
    '    Result := PrepareJSONP(aCallback, Result);\' +
    'End;\' +
    ' \' +
    'Procedure B%1:sControllerClass.Get%0:s%2:s(Const a%0:sID: Integer; ' +
      'Const aCallback: String; Var a%2:sString: String; ' +
      'Var aErrorInfo: BErrorInfoRec);\' +
    'Begin\' +
    '  a%2:sString := Get%0:s%2:s(a%0:sID, aCallback, aErrorInfo);\' +
    'End;\' +
    ' \';

  CODE_PEA_PLURAL_PLAIN_UPDATE =
    'Procedure B%1:sControllerClass.Update%0:s%2:s(Const a%0:sID: Integer; ' +
      'Const a%2:sString: String; Var aErrorInfo: BErrorInfoRec);\' +
    'Var\' +
    '  a%0:s: B%0:sClass;\' +
    '  a%2:s: %3:s;\' +
    'Begin\' +
    '  a%0:s := bManager.GetObject(a%0:sID);\' +
    '  MIf(a%0:s = nil)MThen(1, ''Unable find %0:s'')MExit;\' +
    '  a%2:s := %3:s.Build;\' +
    '  Fill%3:s(a%2:sString, a%2:s);\' +
    '  If aErrorInfo.Code = 0 Then\' +
    '    Try\' +
    '      a%0:s := bManager.ChangeObject(a%0:s);\' +
    '      a%0:s.Load%2:s(a%2:s);\' +
    '      a%0:s.Validate;\' +
    '    Except On E: BExceptionClass Do\' +
    '      aErrorInfo := BuildErrorInfo(E.Code, E.Message);\' +
    '    End;\' +
    '  a%2:s.Burn;\' +
    'End;\' +
    ' \';

  CODE_PEA_PLURAL_PEAS_UPDATE =
    'Procedure B%1:sControllerClass.Update%0:s%2:s(Const a%0:sID: Integer; ' +
      'Const a%2:sString: String; Var aErrorInfo: BErrorInfoRec);\' +
    'Var\' +
    '  i: Integer;\' +
    '  a%0:s: B%0:sClass;\' +
    '  a%3:s: B%3:sClass;\' +
    '  a%4:sIDs: BIntegersList;\' +
    '  a%4:s: B%4:sList;\' +
    '  a%4:sManager: B%4:sManagerClass;\' +
    'Begin\' +
    '  a%0:s := bManager.GetObject(a%0:sID);\' +
    '  MIf(a%0:s = nil)MThen(1, ''Unable find %0:s'')MExit;\' +
    '  a%4:sIDs := BIntegersList.Build;\' +
    '  a%4:s := B%4:sList.Build;\' +
    '  a%4:sManager := B%4:sManagerClass.Build;\' +
    '  FillBIntegersList(a%2:sString, a%4:sIDs);\' +
    '  For i := 0 To a%4:sIDs.Count - 1 Do\' +
    '    Begin\' +
    '      a%3:s := a%4:sManager.GetObject(a%4:sIDs[i]);\' +
    '      If a%3:s = nil Then\' +
    '        Begin\' +
    '          aErrorInfo := BuildErrorInfo(1, ''Unable Find %3:s'');\' +
    '          Break;\' +
    '        End;\' +
    '      a%4:s.Add(a%3:s);\' +
    '    End;\' +
    ' \' +
    '  If aErrorInfo.Code = 0 Then\' +
    '    Try\' +
    '      a%0:s := bManager.ChangeObject(a%0:s);\' +
    '      a%0:s.Load%2:s(a%4:s);\' +
    '      a%0:s.Validate;\' +
    '    Except On E: BExceptionClass Do\' +
    '      aErrorInfo := BuildErrorInfo(E.Code, E.Message);\' +
    '    End;\' +
    '  a%4:sManager.Burn;\' +
    '  a%4:s.Burn;\' +
    '  a%4:sIDs.Burn;\' +
    'End;\' +
    ' \';

  CODE_PEA_PLURAL_HOLDERS_UPDATE =
    'Procedure B%1:sControllerClass.Update%0:s%2:s(Const a%0:sID: Integer; ' +
      'Const a%2:sString: String; Var aErrorInfo: BErrorInfoRec);\' +
    'Var\' +
    '  a%0:s: B%0:sClass;\' +
    '  a%4:s: B%4:sList;\' +
    '  a%4:sCtrl: B%4:sControllerClass;\' +
    'Begin\' +
    '  a%0:s := bManager.GetObject(a%0:sID);\' +
    '  MIf(a%0:s = nil)MThen(1, ''Unable find %0:s'')MExit;\' +
    '  a%4:s := B%4:sList.Build;\' +
    '  a%4:sCtrl := B%4:sControllerClass.Build;\' +
    '  a%4:sCtrl.ParseListJSON(a%2:sString, a%4:s, aErrorInfo);\' +
    '  If aErrorInfo.Code = 0 Then\' +
    '    a%0:s.Load%2:s(a%4:s);\' +
    '  a%4:s.Burn;\' +
    '  a%4:sCtrl.Burn;\' +
    'End;\' +
    ' \';

  CODE_HOLDER_PLURAL_PLAIN_GET =
    'Function B%1:sControllerClass.Get%0:s%2:s(' +
      'Const aOwner: B%1:sOwnerClass; Const a%0:sID: Integer; ' +
      'Const aCallback: String; Var aErrorInfo: BErrorInfoRec): String;\' +
    'Var\' +
    '  i: Integer;\' +
    '  a%0:s: B%0:sClass;\' +
    'Begin\' +
    '  Result := '''';\' +
    '  a%0:s := bManager.GetObject(a%0:sID);\' +
    '  MIf(a%0:s = nil)MThen(1, ''Unable find %0:s'')MExit;\' +
    '  With a%0:s.%2:s.LockList Do\' +
    '    Try\' +
    '      For i := 0 To Count - 1 Do\' +
    '        AppendCommaString(Result, ''%3:s'', [%4:s])\' +
    '    Finally\' +
    '      a%0:s.%2:s.UnlockList;\' +
    '    End;\' +
    '  Result := ''['' + Result + '']'';\' +
    '  If Not(aCallback = '''') Then\' +
    '    Result := PrepareJSONP(aCallback, Result);\' +
    'End;\' +
    ' \' +
    'Procedure B%1:sControllerClass.Get%0:s%2:s(' +
      'Const aOwner: B%1:sOwnerClass; Const a%0:sID: Integer; ' +
      'Const aCallback: String; Var a%2:sString: String; ' +
      'Var aErrorInfo: BErrorInfoRec);\' +
    'Begin\' +
    '  a%2:sString := Get%0:s%2:s(aOwner, a%0:sID, aCallback, aErrorInfo);\' +
    'End;\' +
    ' \';

  CODE_HOLDER_PLURAL_PEAS_GET =
    'Function B%1:sControllerClass.Get%0:s%2:s(' +
      'Const aOwner: B%1:sOwnerClass; Const a%0:sID: Integer; ' +
      'Const aCallback: String; Var aErrorInfo: BErrorInfoRec): String;\' +
    'Var\' +
    '  i: Integer;\' +
    '  a%0:s: B%0:sClass;\' +
    '  a%3:s: B%3:sClass;\' +
    '  a%4:sCtrl: B%4:sControllerClass;\' +
    'Begin\' +
    '  Result := '''';\' +
    '  a%0:s := bManager.GetObject(a%0:sID);\' +
    '  MIf(a%0:s = nil)MThen(1, ''Unable find %0:s'')MExit;\' +
    '  a%4:sCtrl := B%4:sControllerClass.Build;\' +
    '  With a%0:s.%2:s.LockList Do\' +
    '    Try\' +
    '      For i := 0 To Count - 1 Do\' +
    '        If Not(Items[i].Deleted) Then\' +
    '          AppendCommaString(Result, ''{%%s}'', ' +
                 '[a%4:sCtrl.GetJSON(Items[i])]);\' +
    '    Finally\' +
    '      a%4:sCtrl.Burn;\' +
    '      a%0:s.%2:s.UnlockList;\' +
    '    End;\' +
    '  Result := ''['' + Result + '']'';\' +
    '  If Not(aCallback = '''') Then\' +
    '    Result := PrepareJSONP(aCallback, Result);\' +
    'End;\' +
    ' \' +
    'Procedure B%1:sControllerClass.Get%0:s%2:s(' +
      'Const aOwner: B%1:sOwnerClass; Const a%0:sID: Integer; ' +
      'Const aCallback: String; Var a%2:sString: String; ' +
      'Var aErrorInfo: BErrorInfoRec);\' +
    'Begin\' +
    '  a%2:sString := Get%0:s%2:s(aOwner, a%0:sID, aCallback, aErrorInfo);\' +
    'End;\' +
    ' \';

  CODE_HOLDER_PLURAL_HOLDERS_GET =
    'Function B%1:sControllerClass.Get%0:s%2:s(' +
      'Const aOwner: B%1:sOwnerClass; Const a%0:sID: Integer; ' +
      'Const aCallback: String; Var aErrorInfo: BErrorInfoRec): String;\' +
    'Var\' +
    '  i: Integer;\' +
    '  a%0:s: B%0:sClass;\' +
    '  a%3:s: B%3:sClass;\' +
    '  a%4:sCtrl: B%4:sControllerClass;\' +
    'Begin\' +
    '  Result := '''';\' +
    '  a%0:s := aOwner.List.Find(a%0:sID);\' +
    '  MIf(a%0:s = nil)MThen(1, ''Unable find %0:s'')MExit;\' +
    '  a%4:sCtrl := B%4:sControllerClass.Build;\' +
    '  With a%0:s.%2:s.LockList Do\' +
    '    Try\' +
    '      For i := 0 To Count - 1 Do\' +
    '        AppendCommaString(Result, ''{%%s}'', ' +
               '[a%4:sCtrl.GetJSON(Items[i])]);\' +
    '    Finally\' +
    '      a%4:sCtrl.Burn;\' +
    '      a%0:s.%2:s.UnlockList;\' +
    '    End;\' +
    '  Result := ''['' + Result + '']'';\' +
    '  If Not(aCallback = '''') Then\' +
    '    Result := PrepareJSONP(aCallback, Result);\' +
    'End;\' +
    ' \' +
    'Procedure B%1:sControllerClass.Get%0:s%2:s(' +
      'Const aOwner: B%1:sOwnerClass; Const a%0:sID: Integer; ' +
      'Const aCallback: String; Var a%2:sString: String; ' +
      'Var aErrorInfo: BErrorInfoRec);\' +
    'Begin\' +
    '  a%2:sString := Get%0:s%2:s(aOwner, a%0:sID, aCallback, aErrorInfo);\' +
    'End;\' +
    ' \';

  CODE_HOLDER_PLURAL_PLAIN_UPDATE =
    'Procedure B%1:sControllerClass.Update%0:s%2:s(' +
      'Const aOwner: B%1:sOwnerClass; Const a%0:sID: Integer; ' +
      'Const a%2:sString: String; Var aErrorInfo: BErrorInfoRec);\' +
    'Var\' +
    '  a%0:s: B%0:sClass;\' +
    '  a%2:s: %3:s;\' +
    'Begin\' +
    '  a%0:s := aOwner.List.Find(a%0:sID);\' +
    '  MIf(a%0:s = nil)MThen(1, ''Unable find %0:s'')MExit;\' +
    '  a%2:s := %3:s.Build;\' +
    '  Fill%3:s(a%2:sString, a%2:s);\' +
    '  If aErrorInfo.Code = 0 Then\' +
    '    Try\' +
    '      a%0:s := bManager.ChangeObject(a%0:s);\' +
    '      a%0:s.Load%2:s(a%2:s);\' +
    '      a%0:s.Validate;\' +
    '    Except On E: BExceptionClass Do\' +
    '      aErrorInfo := BuildErrorInfo(E.Code, E.Message);\' +
    '    End;\' +
    '  a%2:s.Burn;\' +
    'End;\' +
    ' \';

  CODE_HOLDER_PLURAL_PEAS_UPDATE =
    'Procedure B%1:sControllerClass.Update%0:s%2:s(' +
      'Const aOwner: B%1:sOwnerClass; Const a%0:sID: Integer; ' +
      'Const a%2:sString: String; Var aErrorInfo: BErrorInfoRec);\' +
    'Var\' +
    '  i: Integer;\' +
    '  a%0:s: B%0:sClass;\' +
    '  a%3:s: B%3:sClass;\' +
    '  a%4:sIDs: BIntegersList;\' +
    '  a%4:s: B%4:sList;\' +
    '  a%4:sManager: B%4:sManagerClass;\' +
    'Begin\' +
    '  a%0:s := aOwner.List.Find(a%0:sID);\' +
    '  MIf(a%0:s = nil)MThen(1, ''Unable find %0:s'')MExit;\' +
    '  a%4:sIDs := BIntegersList.Build;\' +
    '  a%4:s := B%4:sList.Build;\' +
    '  a%4:sManager := B%4:sManagerClass.Build;\' +
    '  FillBIntegersList(a%2:sString, a%4:sIDs);\' +
    '  For i := 0 To a%4:sIDs.Count - 1 Do\' +
    '    Begin\' +
    '      a%3:s := a%4:sManager.GetObject(a%4:sIDs[i]);\' +
    '      If a%3:s = nil Then\' +
    '        Begin\' +
    '          aErrorInfo := BuildErrorInfo(1, ''Unable Find %3:s'');\' +
    '          Break;\' +
    '        End;\' +
    '      a%4:s.Add(a%3:s);\' +
    '    End;\' +
    ' \' +
    '  If aErrorInfo.Code = 0 Then\' +
    '    Try\' +
    '      a%0:s := bManager.ChangeObject(a%0:s);\' +
    '      a%0:s.Load%2:s(a%4:s);\' +
    '      a%0:s.Validate;\' +
    '    Except On E: BExceptionClass Do\' +
    '      aErrorInfo := BuildErrorInfo(E.Code, E.Message);\' +
    '    End;\' +
    '  a%4:sManager.Burn;\' +
    '  a%4:s.Burn;\' +
    '  a%4:sIDs.Burn;\' +
    'End;\' +
    ' \';

  CODE_HOLDER_PLURAL_HOLDERS_UPDATE =
    'Procedure B%1:sControllerClass.Update%0:s%2:s(' +
       'Const aOwner: B%1:sOwnerClass; Const a%0:sID: Integer; ' +
      'Const a%2:sString: String; Var aErrorInfo: BErrorInfoRec);\' +
    'Var\' +
    '  a%0:s: B%0:sClass;\' +
    '  a%4:s: B%4:sList;\' +
    '  a%4:sCtrl: B%4:sControllerClass;\' +
    'Begin\' +
    '  a%0:s := aOwner.List.Find(a%0:sID);\' +
    '  MIf(a%0:s = nil)MThen(1, ''Unable find %0:s'')MExit;\' +
    '  a%4:s := B%4:sList.Build;\' +
    '  a%4:sCtrl := B%4:sControllerClass.Build;\' +
    '  a%4:sCtrl.ParseListJSON(a%2:sString, a%4:s, aErrorInfo);\' +
    '  If aErrorInfo.Code = 0 Then\' +
    '    a%0:s.Load%2:s(a%4:s);\' +
    '  a%4:s.Burn;\' +
    '  a%4:sCtrl.Burn;\' +
    'End;\' +
    ' \';

  CODE_PLURAL_PEAS_PARSE =
    '  Function Process%1:s(Const a%1:sString: String; ' +
        'Var a%1:s: B%1:sList): Boolean;\' +
    '  Var\' +
    '    i: Integer;\' +
    '    aBuffer: String;\' +
    '    aNeedParse: Boolean;\' +
    '    a%1:sIDs: BIntegersList;\' +
    '    a%1:sManager: B%1:sManagerClass;\' +
    '    a%1:sCtrl: B%1:sControllerClass;\' +
    '  Begin\' +
    '    Result := FALSE;\' +
    '    If Not(CheckJSItem(a%0:sString, a%1:sString)) Then Exit;\' +
    '    aNeedParse := CheckJSItem(a%0:sString, a%1:sString + rsParse);\' +
    '    GetJSItem(a%0:sString, a%1:sString, aBuffer);\' +
    '    If aNeedParse Then\' +
    '      Try\' +
    '        a%1:sCtrl := B%1:sControllerClass.Build;\' +
    '        a%1:sCtrl.ParseListJSON(aBuffer, a%1:s, aErrorInfo);\' +
    '      Finally\' +
    '        a%1:sCtrl.Burn;\' +
    '      End\' +
    '    Else\' +
    '      Try\' +
    '        a%1:sIDs := BIntegersList.Build;\' +
    '        a%1:sManager := B%1:sManagerClass.Build;\' +
    '        FillBIntegersList(aBuffer, a%1:sIDs);\' +
    '        For i := 0 To a%1:sIDs.Count - 1 Do\' +
    '          a%1:s.Add(a%1:sManager.GetObject(a%1:sIDs[i]));\' +
    '      Finally\' +
    '        a%1:sIDs.Burn;\' +
    '        a%1:sManager.Burn;\' +
    '      End;\' +
    '    Result := TRUE;\' +
    '  End;\' +
    ' \';

  CODE_PLURAL_HOLDERS_PARSE =
    '  Function Process%0:s(Const a%0:sString: String; ' +
        'Var a%0:s: B%0:sList): Boolean;\' +
    '  Var\' +
    '    i: Integer;\' +
    '    aNeedParse: Boolean;\' +
    '    a%0:sCtrl: B%0:sControllerClass;\' +
    '  Begin\' +
    '    ;\' +
    '  End;\' +
    '   \';


Implementation

End.

